<?php
if (!(defined('IN_IA')))
{
    exit('Access Denied');
}

class Home extends WeModuleWxapp
{	public function fwb_del_font($str)		{			$str = htmlspecialchars_decode($str);			$re = preg_replace("/font-family:.*;/i",'',$str);			$re = preg_replace("/font-family:.*\"/i",'"',$re);			return $re;		}
    /**
     * 获取轮播
     */
	public function Adlist() {		global $_W,$_GPC;		$data = pdo_getall('bd_cms_ad', array('uniacid'=>$_W['uniacid'],'is_show'=>1),'', 'order By add_time desc');		foreach($data as &$ad){			$ad['ad_thumb']=tomedia($ad['ad_thumb']);		}		$this->result(0, '广告列表', $data);	}	/**	 *  获取banner列表	 */	public function Bannerlist() {	    global $_W,$_GPC;	    $psize=$_GPC['size'];	    if(!$psize){	        $psize=4;	    }	    $data = pdo_getall('bd_banner', array('uniacid'=>$_W['uniacid'],'is_show'=>1),'', 'order By banner_sort limit 0,'.$psize.' desc');	    foreach($data as &$ad){	        $ad['banner_thumb']=tomedia($ad['banner_thumb']);	    }	    $this->result(0, 'banner列表', $data);	}	/**	 *  获取公告列表	 */	public function Noticelist() {	    global $_W, $_GPC;	    $query = load()->object('query');	    $article_list=$query->from('bd_cms_notice')->where(['uniacid'=>$_W['uniacid'],'is_show'=>1]);	    if($_GPC['notice_title']){	        $notice_list = $notice_list->where(' notice_title like',"%{$_GPC['notice_title']}%");	    }	    $beginPage=0;	    if($_GPC['page']>=1){	        $beginPage=$_GPC['page'];	    }	    $size=10;	    if($_GPC['size']){	        $size=$_GPC['size'];	    }	    $begin=$beginPage*$size;		    $notice_list = $notice_list->limit($begin,$size);	    $notice_list=$notice_list->orderby('notice_sort', 'DESC')->getall();	    foreach($notice_list as &$ad){	        $ad['notice_thumb']=tomedia($ad['notice_thumb']);	        $ad['notice_content']=$this->fwb_del_font($ad['notice_content']);	    }	    $this->result(0, '文章列表', $notice_list);	}	/**	 *  获取公告详情	 */	public function Noticeinfo() {	    global $_W, $_GPC;	    $id = intval($_GPC['notice_id']);	    $data = pdo_get('bd_cms_notice', array('notice_id'=>$id, 'uniacid'=>$_W['uniacid']));	    if($data){	        $data['notice_thumb']=tomedia($data['notice_thumb']);	        $this->result(0, '获取文章单条日记',$data);	    }else {	        $this->result(1, '获取文章单条日记',$data);	    }	    	    	}	/**	 *  获取文章列表	 */	public function Articlelist() {		global $_W, $_GPC;		$query = load()->object('query');		$article_list=$query->from('bd_cms_article')->where(['uniacid'=>$_W['uniacid'],'is_show'=>1]);	    if($_GPC['article_title']){             $article_list = $article_list->where(' article_title like',"%{$_GPC['article_title']}%");        }	    if($_GPC['article_cat']){             $article_list = $article_list->where(['article_cat'=>$_GPC['article_cat']]);        }        $beginPage=0;        if($_GPC['page']>=1){        	$beginPage=$_GPC['page'];        }        $size=10;        if($_GPC['size']){        	$size=$_GPC['size'];        }        $begin=$beginPage*$size;                $article_list = $article_list->limit($begin,$size);		$article_list=$article_list->orderby('article_sort', 'DESC')->getall();		foreach($article_list as &$ad){			$ad['article_thumb']=tomedia($ad['article_thumb']);			$ad['article_content']=$this->fwb_del_font($ad['article_content']);		}		$this->result(0, '文章列表', $article_list);	}	/**	 *  获取文章详情	 */	public function Articleinfo() {		global $_W, $_GPC;		$id = intval($_GPC['article_id']);		$data = pdo_get('bd_cms_article', array('article_id'=>$id, 'uniacid'=>$_W['uniacid']));		$data['article_thumb']=tomedia($data['article_thumb']);		$res=pdo_get('bd_favorites', array('fav_type'=>'article','type_key'=>$id,'uniacid'=>$_W['uniacid'],'open_id'=>$_W['openid']));		$data['IsFavorite']=0;		if($res){			$data['IsFavorite']=1;		}		$this->result(0, '获取文章单条日记',$data);	}		/**获取产品列表  */	public function Productlist(){		global $_W,$_GPC;		$query = load()->object('query');		$product_list=$query->from('bd_mis_product')->where(['uniacid'=>$_W['uniacid'],'is_show'=>1]);	    if($_GPC['product_name']){             $product_list = $product_list->where(' product_name like',"%{$_GPC['product_name']}%");        }	    if($_GPC['product_type']){             $product_list = $product_list->where(['product_type'=>$_GPC['product_type']]);        }        $beginPage=0;        if($_GPC['page']>=1){        	$beginPage=$_GPC['page'];        }        $size=10;        if($_GPC['size']){        	$size=$_GPC['size'];        }                $begin=$beginPage*$size;                $product_list = $product_list->limit($begin,$size);		$product_list=$product_list->orderby('add_time', 'DESC')->getall();		foreach($product_list as &$ad){			$ad['product_thumb']=tomedia($ad['product_thumb']);		}		$this->result(0, 'ok',$product_list);			}	/**	 *  获取产品详情	 */	public function Productinfo() {		global $_W,$_GPC;		$id = intval($_GPC['product_id']);		$data = pdo_get('bd_mis_product', array('product_id'=>$id, 'uniacid'=>$_W['uniacid']));		$data['product_thumb']=tomedia($data['product_thumb']);		$this->result(0, '产品信息',$data);	}			public function Configlist(){		global $_W, $_GPC;		$config_group='enterprise';		if($_GPC['config_group']){			$config_group=$_GPC['config_group'];		}			$list=pdo_getall('bd_sys_config',array('uniacid'=>$_W['uniacid'],'config_group'=>$config_group,'status'=>1));			$config_row=array();		foreach ($list as &$conf){			$config_row[$conf['config_code']]=$conf['config_value'];		}		$config_row['enterprise_pic']=tomedia($config_row['enterprise_pic']);		$config_row['enterprise_logo']=tomedia($config_row['enterprise_logo']);		$config_row['enterprise_qrcode']=tomedia($config_row['enterprise_qrcode']);		$config_row['config_group']=$config_group;		$this->result(0, '公司配置内容', $config_row);	}		/**	 *  收藏列表	 */	public function Favoritelist() {		global $_W,$_GPC;		$query = load()->object('query');		$fav_list=$query->from('bd_favorites')->where(['uniacid'=>$_W['uniacid'],'open_id'=>$_W['openid']]);		$beginPage=0;		if($_GPC['page']>=1){			$beginPage=$_GPC['page'];		}		$size=10;		if($_GPC['size']){			$size=$_GPC['size'];		}				$begin=$beginPage*$size;				$fav_list = $fav_list->limit($begin,$size);		$fav_list=$fav_list->orderby('add_time', 'DESC')->getall();				$fav_arr['article']=array();		$fav_arr['product']=array();		$fav_arr['case']=array();		$fav_arr['business']=array();		foreach($fav_list as &$fav){		    if($fav['fav_type']=='article'){		        $fav_arr['article'][]=pdo_get('bd_cms_article',array('article_id'=>$fav['type_key'],'uniacid'=>$_W['uniacid']),array('article_id','article_title','article_desc','article_thumb','add_time'));		        foreach ($fav_arr['article'] as &$art){		            $art['article_thumb']=tomedia($art['article_thumb']);		        }		    }elseif($fav['fav_type']=='product'){		        $fav_arr['product'][]=pdo_get('bd_mis_product',array('product_id'=>$fav['type_key'],'uniacid'=>$_W['uniacid']),array('product_id','product_name','product_current_price','product_thumb','add_time'));		        foreach ($fav_arr['product'] as &$art){		            $art['product_thumb']=tomedia($art['product_thumb']);		        }		    }elseif($fav['fav_type']=='case'){		        $fav_arr['case'][]=pdo_get('bd_mis_case',array('case_id'=>$fav['type_key'],'uniacid'=>$_W['uniacid']),array('case_id','case_name','case_thumb','add_time'));		        foreach ($fav_arr['case'] as &$art){		            $art['case_thumb']=tomedia($art['case_thumb']);		        }		    }else{		        $fav_arr['business'][]=pdo_get('bd_mis_business',array('business_id'=>$fav['type_key'],'uniacid'=>$_W['uniacid']),array('business_id','business_name','business_desc','business_thumb','add_time'));		        foreach ($fav_arr['business'] as &$art){		            $art['business_thumb']=tomedia($art['business_thumb']);		        }		    }		    		}		$this->result(0, 'ok',$fav_arr);	}		/**	 *  添加和取消收藏	 */	public function Favoritedo() {		global $_W, $_GPC;		$fav_type = $_GPC['fav_type'];		$type_key = $_GPC['type_key'];		$IsFavorite = $_GPC['IsFavorite'];		$open_id = $_W['openid'];		if($IsFavorite==1){			$res = pdo_insert('bd_favorites', array('fav_type'=>$fav_type, 'type_key'=>$type_key,'open_id'=>$open_id,					'add_time'=>date('Y-m-d H:i:s'), 'last_time'=>date('Y-m-d H:i:s'),					'uniacid'=>$_W['uniacid'],'uid'=>$_W['uid']));			$message='收藏成功';		}else{			$res = pdo_delete('bd_favorites', array('fav_type'=>$fav_type, 'type_key'=>$type_key,'open_id'=>$open_id));			$message='收藏已取消';		}				if ($res) {			$this->result(0, $message, $res);return;		}else{			$this->result(0, '添加失败');		}	}		/**	 *  保存留言内容	 */	public function Guestbookadd() {	    global $_W;	    $name = $_GET['name'];	    $tel = $_GET['tel'];	    $email = $_GET['email'];	    $content = $_GET['content'];		    $insert = pdo_insert('bd_cms_guestbook', array('guestbook_name'=>$name, 'guestbook_tel'=>$tel,'guestbook_email'=>$email,	        'guestbook_content'=>$content, 'add_time'=>date('Y-m-d H:i:s'), 'last_time'=>date('Y-m-d H:i:s'),	        'uniacid'=>$_W['uniacid'],'uid'=>$_W['uid']));		    if ($insert) {	        $this->result(0, 'message', $insert);	        return;	    }	    $this->result(0, '添加失败');	}		
}
?>